﻿using Microsoft.EntityFrameworkCore;
using Ordering.Domain.SeedWork;
using Ordering.Infrastructure;

namespace Ordering.Domain.Aggregate
{
    [Injection(typeof(IBuyerStogage))]
    public class BuyerStogage
        : IBuyerStogage
    {
        private readonly OrderingDbContext _context;

        public BuyerStogage(OrderingDbContext context)
        {
            _context = context;
        }

        public IUnitOfWork UnitOfWork => _context;

        public void Add(Buyer order)
        {
            _context.Add(order);
        }

        public async Task<Buyer> GetByIdAsync(string id)
        {
            return await _context.Buyers
                .FirstAsync(a => a.Id == id);
        }

        public void Remove(Buyer order)
        {
            _context.Remove(order);
        }

        public void Update(Buyer order)
        {
            _context.Update(order);
        }
    }
}
